<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <p>flag:{{flag}}</p>
        <input type="checkbox" v-model="flag"><br>
        <my-checkbox :model="flag" @updata:model="updataFlag"></my-checkbox>
        <hr>
        <p>flag1:{{flag1}}</p>
        <input type="checkbox" true-value="是" false-value="否" v-model="flag1">
        <my-checkbox 
            true-value="是" 
            false-value="否"
            :model="flag1"
            @updata:model="updataFlag1"
        >
        </my-checkbox>
        <hr>
        <p>arr:{{arr}}</p>
        <input type="checkbox"  value="A" v-model="arr">
        <input type="checkbox" value="B" v-model="arr">
        <input type="checkbox"  value="C" v-model="arr">
        <input type="checkbox" value="D" v-model="arr">
        <br>
        <my-checkbox value="A" :model="arr" @updata:model="updataArr"></my-checkbox>
        <my-checkbox value="B" :model="arr" @updata:model="updataArr"></my-checkbox>
        <my-checkbox value="C" :model="arr" @updata:model="updataArr"></my-checkbox>
        <my-checkbox value="D" :model="arr" @updata:model="updataArr"></my-checkbox>
        
    </div>
    <script type="text/x-template" id="checkbox">
        <input type="checkbox"
         :value="value"
         :true-value="trueValue"
         :false-value="falseValue"
         v-model="state"
         >
    </script>
    <script type="module">
        import { createApp } from "../assets/vue3/vue.esm-browser.js";
        const MyCheckbox={
            template:"#checkbox",
            emits:["updata:model"],
            props:{
                value:{
                    type:String,
                    default:''
                },
                trueValue:{
                    default:true
                },
                falseValue:{
                    default:false
                },
                model:{
                    default(){
                        return []
                    }
                }
            },
            computed:{
                state:{
                    get(){
                        return this.model
                    },
                    set(nv){
                        this.$emit("updata:model",nv)
                    }
                }
            }
        }
        createApp({
            data() {
                return {
                    flag:true,
                    flag1:"是",
                    arr:["A"]
                }
            },
            methods:{
                updataFlag(nv){
                    this.flag=nv
                },
                updataFlag1(nv){
                    this.flag1=nv
                },
                updataArr(nv){
                    this.arr=nv
                }
            },
            components:{
                MyCheckbox
            }
        }).mount("#app");
    </script>
</body>
</html>